<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
require_once("Writer.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Incident_List extends Page
{
       public $lblmodel = null;
       public $lblmake = null;
       public $Label43 = null;
       public $Label38 = null;
       public $lblyear = null;
       public $lblplate = null;
       public $lblEmpName = null;
       public $lblEmpId = null;
       public $JTJSEmission = null;
       public $edtSearchJournal = null;
       public $JTJournal = null;
       public $JTIncidentHidden = null;
       public $imageAddJournal = null;
       public $btnExportIncident = null;
       public $btnSearch = null;
       public $Image4 = null;
       public $Label48 = null;
       public $lblVeh = null;
       public $JTJavaScript1 = null;
       public $imgBack = null;
       public $Image3 = null;
       public $hiddenId = null;
       public $JTSiteTheme1 = null;
       function edtSearchJournalJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('edtSearchJournal').value = '';
       <?php

       }

       function btnExportIncidentJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['btnExportIncident'].src="image/excel.png"
       <?php

       }

       function btnExportIncidentJSMouseOver($sender, $params)
       {

       ?>
       document.images['btnExportIncident'].src="image/excel2.png"

       <?php

       }

       function btnExportIncidentClick($sender, $params)
       {
       $this->JTIncidentHidden->exportGridToXLSDownload('incident_report.xls');


       }



       function imageAddJournalJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imageAddJournal'].src="image/add_new.png"
       <?php

       }

       function imageAddJournalJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imageAddJournal'].src="image/add_new_blue.png"
       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }


       function commafy($_)
       {
        return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,' , strrev( $_ ) ) );
       }







          function JTIncidentHiddenShow($sender, $params)
       {

       $result_vin = mysql_query("SELECT * FROM vehicle_tbl WHERE vehicle_id='" .$this->hiddenId->getValue(). "'");
       $row_selected = mysql_fetch_array($result_vin);


       $arr = array();


       $arr[] = array(
                        '1' => 'Plate Num:'.' '.$row_selected['veh_num'],
                        '2'=> ' ',
                        '3' => ' ',
                        '4' => ' ',
                        '5'=>''
                    );

       $arr[] = array(
                        '1' => 'Year:'.' '.$row_selected['year'],
                        '2'=>' ',
                        '3' => ' ',
                        '4' => ' ',
                        '5'=>''
                    );

       $arr[] = array(
                        '1' => 'Make:'.' '.$row_selected['manufacturer_name'],
                        '2'=>' ',
                        '3' => ' ',
                        '4' => ' ',
                        '5'=>''
                    );

       $arr[] = array(
                        '1' => 'Model:'.' '.$row_selected['model_name'],
                        '2'=> ' ',
                        '3' => ' ',
                        '4' => ' ',
                        '5'=>''
                    );

       $arr[] = array(
                        '1' => 'Type/Style:'.' '.$row_selected['style_name'],
                        '2'=> ' ',
                        '3' => ' ',
                        '4' => ' ',
                        '5'=>''
                    );

       $arr[] = array(
                        '1' => ' ',
                        '2'=>' ',
                        '3' => ' ',
                        '4' => ' ',
                        '5'=>''
                    );



       $query1 = "select * from veh_incident_tbl where company_id='".$_SESSION['company_id']."' and vehicle_id='".$this->hiddenId->getValue()."' order by date desc";
       $result = mysql_query($query1)or die(mysql_error());

       $arr[] = array(
                        '1' => 'INCIDENT REPORT',
                        '2'=>' ',
                        '3' => ' ',
                        '4' => ' ',
                        '5' => '',
                    );

       $arr[] = array(
                        '1' => 'Incident No.',
                        '2' => 'Incident Date',
                        '3' => 'Description',
                        '4' => 'Incident Type',
                        '5' => 'Driver'
                        );

       while($row_journal = mysql_fetch_array($result))
       {
         $journal_id = $row_journal['incident_id'];
         $journal_edit = "<a href=veh_journal_edit.php?veh=".$this->hiddenId->getValue()."&journal=".$journal_id." title='edit journal'>".$row_journal['date']."</a>";
         $tools_journal = "<img onclick=js_deleteJournal('".$this->hiddenId->getValue()."','".$journal_id."'); src='image/delete.png' title='delete'>";
         //"<a href=veh_journal_delete.php?veh=".$this->hiddenId->getValue()."&journal=".$journal_id."><img src='image/delete_orange.jpg' title='delete' no border></a>";


          $arr[] = array(
                        '1' => $row_journal['incident_num'],
                        '2' => $row_journal['date'],
                        '3' => $row_journal['description'],
                        '4' => $row_journal['type'],
                        '5' => $row_journal['driver']
                        );
       }

       $this->JTIncidentHidden->setCellData($arr);


       }


       function JTJournalShow($sender, $params)
       {
       //$this->edtSearchJournal->setText($_GET['search_journal']);
       $query1 = "select * from veh_incident_tbl where company_id='".$_SESSION['company_id']."' and vehicle_id='".$this->hiddenId->getValue()."' and (date like '%".$this->edtSearchJournal->Text."%'
        or type like '%".$this->edtSearchJournal->Text."%'
        or description like '%".$this->edtSearchJournal->Text."%'
        or driver like '%".$this->edtSearchJournal->Text."%'
        or cost like '%".$this->edtSearchJournal->Text."%'
        or ref_num like '%".$this->edtSearchJournal->Text."%'
        or comments like '%".$this->edtSearchJournal->Text."%'
        or incident_num like '%".$this->edtSearchJournal->Text."%') order by incident_id ASC";
       $result = mysql_query($query1)or die(mysql_error());

       $arr = array();
       while($row_journal = mysql_fetch_array($result))
       {
         $journal_id = $row_journal['incident_id'];
         $journal_edit = "<a href=veh_incident_edit.php?veh=".$this->hiddenId->getValue()."&journal=".$journal_id." title='edit incident report'>".$row_journal['incident_num']."</a>";


         //"<a href=veh_journal_delete.php?veh=".$this->hiddenId->getValue()."&journal=".$journal_id."><img src='image/delete_orange.jpg' title='delete' no border></a>";

         $tools_journal = "<img onclick=js_deleteJournal('".$this->hiddenId->getValue()."','".$journal_id."'); src='image/delete.png' title='delete' style='cursor:pointer'>";


         if($_SESSION['access_vehicle']==1)
         {
         $arr[] = array(
                        'Incident No.' => $journal_edit,
                        'Incident Date' => $row_journal['date'],
                        'Description' => $row_journal['description'],
                        'Incident Type' => $row_journal['type'],
                        'Driver' => $row_journal['driver']
                        );
         }
         if($_SESSION['access_vehicle']==2)
         {
         $arr[] = array(
                        'Incident No.' => $journal_edit,
                        'Incident Date' => $row_journal['date'],
                        'Description' => $row_journal['description'],
                        'Incident Type' => $row_journal['type'],
                        'Driver' => $row_journal['driver'],
                        'Tools' => $tools_journal
                        );
         }
       }

       $this->JTJournal->setCellData($arr);


       }




       function Incident_ListCreate($sender, $params)
       {
       /*if($_SESSION['isAdmin']!=1)
       {
        $this->imgAddExpense->setVisible(false);
        $this->btnExport->Left = 943;
       }

       if($_SESSION['isAdmin']==1)
       {
        $this->imgAddExpense->setVisible(true);
        $this->btnExport->Left = 838;
       }*/

       $id = $_GET['veh'];
       if(isset($id) && ($id!='' || $id!=null))
       $this->hiddenId->setValue($id);

       if($_SESSION['access_vehicle']==1)
       {
       $this->imageAddJournal->Visible=false;
       $this->btnExportIncident->Left=948;
       }

       if($_SESSION['access_vehicle']==2)
       {
       $this->imageAddJournal->Visible=true;
       $this->btnExportIncident->Left=847;
       }

       $result_vin = mysql_query("SELECT * FROM vehicle_tbl WHERE vehicle_id='" .$this->hiddenId->getValue(). "'");
       $row_selected = mysql_fetch_array($result_vin);
       $label = $row_selected['VIN'];
       $this->lblVeh->Caption = $label;
       $this->lblyear->Caption = $row_selected['year'];
       $this->lblmake->Caption = $row_selected['manufacturer_name'];
       $this->lblmodel->Caption = $row_selected['model_name'];
       $this->lblplate->Caption = $row_selected['veh_num'];

       $this->imgBack->setLink('vehicle_list.php?company='.$_SESSION['company_id']);
       //$this->imgAddExpense->setLink('veh_expense_create.php?veh='.$this->hiddenId->getValue());
       $this->imageAddJournal->setLink('veh_incident_create.php?veh='.$this->hiddenId->getValue());

       }



}

global $application;

global $Incident_List;

//Creates the form
$Incident_List=new Incident_List($application);

//Read from resource file
$Incident_List->loadResource(__FILE__);

//Shows the form
$Incident_List->show();

?>